package com.meritit.portal.operlog.web;

import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.meritit.portal.operlog.bean.TPOperlog;
import com.meritit.portal.operlog.service.OperlogFactory;
import com.meritit.portal.operlog.service.OperlogIntfs;
import com.meritit.portal.util.DateUtils;
import com.meritit.portal.util.Encrypt;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 公司: 西安美林电子有限责任公司
 * 作者：baixw，Oct 24, 2011
 * 描述：
 * 说明: 
 */
public class AOperLog extends ActionSupport{
    private Logger log = Logger.getLogger(AOperLog.class);
    private OperlogIntfs logMgr = OperlogFactory.getSysLogService(); 
    private static final long serialVersionUID = -6020733308442832155L;
    
    public String addLog() throws Exception{
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setCharacterEncoding("UTF-8");
        String info =request.getParameter("info");
        info = URLDecoder.decode(info, "UTF-8");
        String[] data = {"",""};
        if(info!=null && !"".equals(info)){
        	data = info.split("@");
        }
        String userNewId = (String)request.getParameter("userId");
        String currDate = DateUtils.getCurrDateStr();
		String userId = Encrypt.decrypt(currDate, userNewId);
        String timeStr = DateUtils.getCurrDateTimeStr();
        TPOperlog tplog = new TPOperlog();
        tplog.setOperdateD(timeStr);
        tplog.setUsername(userId);
        tplog.setModuleV("业务入口");
        tplog.setFunctionV("业务入口");
        tplog.setStationnameV("普通用户");
        tplog.setDataV(data[1]);
        tplog.setHasexceptionV("否");
        tplog.setOperationV(data[0]);
        try {
            logMgr.saveOperlog(tplog);
        } catch (Exception e) {
            log.error("添加用户操作日志失败",e);
            throw e;
        }
        return null;
    }
    public String addMgrLog() throws Exception{
        HttpServletRequest request = ServletActionContext.getRequest();
        request.setCharacterEncoding("UTF-8");
        String info =request.getParameter("info");
        info = URLDecoder.decode(info, "UTF-8");
        String[] data = {"",""};
        if(info!=null && !"".equals(info)){
        	data = info.split("@");
        }
        String userNewId = (String)request.getParameter("userId");
        String currDate = DateUtils.getCurrDateStr();
		String userId = Encrypt.decrypt(currDate, userNewId);
        String timeStr = DateUtils.getCurrDateTimeStr();
        TPOperlog tplog = new TPOperlog();
        tplog.setOperdateD(timeStr);
        tplog.setUsername(userId);
        tplog.setModuleV("业务入口");
        tplog.setFunctionV("业务入口");
        tplog.setStationnameV("系统管理员");
        tplog.setDataV(data[1]);
        tplog.setHasexceptionV("否");
        tplog.setOperationV(data[0]);
        try {
            logMgr.saveOperlog(tplog);
        } catch (Exception e) {
            log.error("添加用户操作日志失败",e);
            throw e;
        }
        return null;
    }
}
